﻿CREATE PROCEDURE [ServiceEngine].[CreateSoapFaultForOperationVersion]
	@OperationVersionID uniqueidentifier,
	@Name nvarchar(400),
	@Action nvarchar(256),
	@ProtectionLevel nvarchar(32),
	@SchemaObjectID uniqueidentifier,
	@ID uniqueidentifier OUTPUT
AS
BEGIN
	DECLARE @ErrorMessage NVARCHAR(4000);
	DECLARE @ErrorSeverity INT;
	DECLARE @ErrorState INT;
	SET NOCOUNT ON;

	SET @ID = newid();

	BEGIN TRY
		BEGIN TRANSACTION

		INSERT INTO ServiceEngine.SoapFaults (OperationVersionID,SoapFaultID, Name, Action, ProtectionLevel, SchemaObjectID)
		VALUES (@OperationVersionID,@ID, @Name, @Action,@ProtectionLevel, @SchemaObjectID)

		COMMIT TRANSACTION
	END TRY
	BEGIN CATCH
		SELECT 
			@ErrorMessage = ERROR_MESSAGE(),
			@ErrorSeverity = ERROR_SEVERITY(),
			@ErrorState = ERROR_STATE();

		IF XACT_STATE() <> 0 ROLLBACK TRANSACTION;

		RAISERROR (@ErrorMessage, 
				   @ErrorSeverity,
				   1);
	END CATCH
END


